package com.zuthub.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zuthub.common.annotation.Log;
import com.zuthub.common.core.controller.BaseController;
import com.zuthub.common.core.domain.AjaxResult;
import com.zuthub.common.enums.BusinessType;
import com.zuthub.system.domain.SysHonor;
import com.zuthub.system.service.ISysHonorService;
import com.zuthub.common.utils.poi.ExcelUtil;
import com.zuthub.common.core.page.TableDataInfo;

/**
 * 光荣榜Controller
 * 
 * @author zuthub
 * @date 2021-04-02
 */
@RestController
@RequestMapping("/system/honor")
public class SysHonorController extends BaseController
{
    @Autowired
    private ISysHonorService sysHonorService;

    /**
     * 查询光荣榜列表
     */
    @PreAuthorize("@ss.hasPermi('system:honor:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysHonor sysHonor)
    {
        startPage();
        List<SysHonor> list = sysHonorService.selectSysHonorList(sysHonor);
        return getDataTable(list);
    }

    @GetMapping("/tourist")
    @CrossOrigin
    public TableDataInfo listForTourist(SysHonor sysHonor)
    {
        startPage();
        List<SysHonor> list = sysHonorService.selectSysHonorList(sysHonor);
        return getDataTable(list);
    }

    /**
     * 导出光荣榜列表
     */
    @PreAuthorize("@ss.hasPermi('system:honor:export')")
    @Log(title = "光荣榜", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysHonor sysHonor)
    {
        List<SysHonor> list = sysHonorService.selectSysHonorList(sysHonor);
        ExcelUtil<SysHonor> util = new ExcelUtil<SysHonor>(SysHonor.class);
        return util.exportExcel(list, "honor");
    }

    /**
     * 获取光荣榜详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:honor:query')")
    @GetMapping(value = "/{honorId}")
    public AjaxResult getInfo(@PathVariable("honorId") Long honorId)
    {
        return AjaxResult.success(sysHonorService.selectSysHonorById(honorId));
    }

    /**
     * 新增光荣榜
     */
    @PreAuthorize("@ss.hasPermi('system:honor:add')")
    @Log(title = "光荣榜", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysHonor sysHonor)
    {
        return toAjax(sysHonorService.insertSysHonor(sysHonor));
    }

    /**
     * 修改光荣榜
     */
    @PreAuthorize("@ss.hasPermi('system:honor:edit')")
    @Log(title = "光荣榜", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysHonor sysHonor)
    {
        return toAjax(sysHonorService.updateSysHonor(sysHonor));
    }

    /**
     * 删除光荣榜
     */
    @PreAuthorize("@ss.hasPermi('system:honor:remove')")
    @Log(title = "光荣榜", businessType = BusinessType.DELETE)
	@DeleteMapping("/{honorIds}")
    public AjaxResult remove(@PathVariable Long[] honorIds)
    {
        return toAjax(sysHonorService.deleteSysHonorByIds(honorIds));
    }
}
